<?php
/*========================================= JooSam =========================================/
/																							/
/	Extention:		JooSam																	/
/	Created by:		Broadcastweb.eu - Paules												/
/	Site:			http://www.broadcastweb.eu												/
/	Email:			support@broadcastweb.eu													/
/	Copyright:		2011 - 2012 (c) Broadcastweb.eu											/
/	License:		CC BY-NC-ND 3.0 ~ http://creativecommons.org/licenses/by-nc-nd/3.0/		/
/	File Version:	0003																	/
/																							/
/========================================== JooSam ========================================*/
// Joomla Security
defined('_JEXEC') or die;
JHtml::_('behavior.tooltip');

$sid = JRequest::getVar('jsm_hidden_songid', 0);
if($sid > 0):
	$data = new RequestHelper();
	$req = $data->request($sid);
	//$req = (object) array('code' => 200, 'txt' => 'Request OK.', 'songid' => 4352, 'request' => 45, 'msg' => 2);
	$reqCode = $req->code;
	$reqTxt = $req->txt;
	$reqSong = $req->songid;
	$reqRequest = $req->request;
	$reqMessage = $req->msg; ?>

	<div id="jsm_message" style="text-align:center; margin:0 auto;">
		<h4 style="margin:4px 0 10px 0;"><?php echo $reqTxt; ?></h4>
	</div> <?php

	if($reqCode == 200 and $reqMessage > 0 and $reqRequest > 0):
		if($reqMessage == 2){
			$nametxt = JText::_('COM_JOOSAM_VIEW_REQUEST_ENTERNAME_REQ');
		} else{
			$nametxt = JText::_('COM_JOOSAM_VIEW_REQUEST_ENTERNAME_NOREQ');
		}?>

		<div id="jsm_thanksform">
			<script>document.getElementById('jsm_hidden_pageload').value = 'request';</script>
			<input type="hidden" id="jsm_reqid" name="jsm_reqid" value="<?php echo $reqRequest; ?>"/>
			<div id="jsm_reqnameinp" style="text-align:center;">
				<label for="jsm_clientname" id="jsm_clientname_label"><?php echo JText::_('COM_JOOSAM_VIEW_REQUEST_NAME'); ?></label>
				<input type="text" id="jsm_clientname" name="jsm_clientname" title="<?php echo $nametxt; ?>" value="" onkeypress="joosam.keycheck(event);" onkeypress="return false;"/>
			</div>
			<div id="jsm_reqmsginp" style="text-align:center; margin:0 auto;">
				<textarea name="jsm_clientmsg" id="jsm_clientmsg" cols="60" rows="10" onkeyup="jsm_messagecount();" class="textarea" style="height:170px; margin: 5px 0 0 0; padding:2px;"></textarea>
			</div>
		</div> <?php
	endif;
else: ?>
	<div id="jsm_message" style="text-align:center; margin:0 auto;">
		<h4 style="margin:4px 0 10px 0;"><?php echo JText::_('COM_JOOSAM_VIEW_REQUEST_ERR_SID'); ?></h4>
	</div><?php
endif; ?>

<div style="text-align:center; margin:0 auto;">
	<input type="hidden" id="jsm_msgtype" name="jsm_msgtype" value="<?php echo $reqMessage; ?>"/><?php
	if($reqCode == 200 and $reqMessage > 0 and $reqRequest > 0): ?>
		<input type="submit" value="<?php echo JText::_('COM_JOOSAM_VIEW_REQUEST_SEND'); ?>" onclick="return jsm_sendmsg();" style="height:20px;"/>
		<span id="jsm_messagecount" style="padding:0 10px;">0/150</span> <?php
	endif; ?>
	<input type="submit" value="<?php echo JText::_('COM_JOOSAM_VIEW_REQUEST_GOBACK'); ?>" onclick="return jsm_goback();" style="height:20px;"/>
</div>

<script>
	
	function jsm_goback(){
		document.getElementById('jsm_hidden_pageload').value = 'home';
		document.getElementById('jsm_form').submit();
	}
	function jsm_sendmsg(){
		var msgtype = <?php echo $reqMessage; ?>;
		var msgName = document.getElementById('jsm_clientname');
		var msgText = document.getElementById('jsm_clientmsg');
		var textout = '';

		if((msgtype == 2) && (msgName.value == '')){
			textout = textout+'\n\r<?php echo JText::_("COM_JOOSAM_VIEW_REQUEST_SCRIPT_NAME_REQUIRED"); ?>';
		}
		if(msgText.value == ''){
			textout = textout+'\n\r<?php echo JText::_("COM_JOOSAM_VIEW_REQUEST_SCRIPT_NOMSG"); ?>';
		}

		if(textout == ''){
			document.getElementById('jsm_hidden_pageload').value = 'thanks';
			document.getElementById('jsm_form').submit();
			return true;
		} else{
			alert(textout);
			return false;
		}
	}
	function jsm_messagecount(){

		var maxchars = 150;
		var source = document.getElementById('jsm_clientmsg');
		var disp = document.getElementById('jsm_messagecount');
		var textString = source.value;
		var textlength = textString.length;

		if(textlength > maxchars){
			source.value = textString.substr(0, maxchars);
			textlength = maxchars;
			alert('<?php echo JText::_("COM_JOOSAM_VIEW_REQUEST_SCRIPT_MAXCHAR"); ?>'+maxchars);
		}
		disp.innerHTML = textlength+'/'+maxchars;
	}			
</script>
		